#!/usr/bin/python
import subprocess
import shutil
import sys
import os

majorversion = 2.1

build = subprocess.check_output(['hg', 'id', '-n'])
build = build.replace('\n', '')
version = "%s.%s" % (majorversion, build)
print "Building version %s" % repr(version)

if '+' in version:
    print "Uncommitted updates found"
#   sys.exit(1)

f = open('version.txt', 'w')
f.write('%s\n' % version)
f.close()

shutil.rmtree('build', ignore_errors=True)
shutil.rmtree('dist', ignore_errors=True)
subprocess.check_call(['c:\python27\python.exe', 'setup.py', 'py2exe'])
subprocess.check_call(['c:\program files (x86)\NSIS\makensis.exe', 'ptz.nsi'])
shutil.rmtree('build')

vername = 'ptz-%s-setup.exe' % version 
try:
    os.unlink(vername)
except:
    pass
os.rename('ptz-setup.exe', vername) 
